﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using BlueCMS.Core.Data.Query.Clauses;

namespace BlueCMS.Core.Data.Query.Columns
{
    public class OrderByColumn : Column, IOrderByColumn
    {
        public OrderByType Type { get; set; }
        public SortDirection SortDirection { get;  set; }
        OrderByClause Clause { get; set; }

        public OrderByColumn(object nameOrExpression, OrderByType type, OrderByClause clause)
            : base(nameOrExpression)
        {
            Type = type;
            Clause = clause;
        }

        IOrderByClause IOrderByColumn.Descending()
        {
            SortDirection = SortDirection.Descending;
            return Clause;
        }

        IOrderByColumn IOrderByColumn.Column(string name)
        {
            OrderByColumn column = new OrderByColumn(name, OrderByType.Column, Clause);
            Clause.OrderByColumns.Add(column);
            return column;
        }

        IOrderByColumn IOrderByColumn.Alias(string alias)
        {
            OrderByColumn column = new OrderByColumn(alias, OrderByType.Alias, Clause);
            Clause.OrderByColumns.Add(column);
            return column;
        }

        IOrderByColumn IOrderByColumn.Index(int index)
        {
            OrderByColumn column = new OrderByColumn(index, OrderByType.Index, Clause);
            Clause.OrderByColumns.Add(column);
            return column;
        }
    }
}
